/*
 * $Id: ssh2.h 9ce65bed8ef4 2012/08/26 02:14:51 pgurumur $
 * Copyright (c) 2012 Prabhu Gurumurthy <pgurumur@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *

 * __version__  = "$Revision: 9ce65bed8ef4 $"
 * __author__   = "$Author: pgurumur $"
 * __modified__ = "$Date: 2012-08-26 02:14:51Z $"
 */
#ifndef __SSHC_H_
#define __SSHC_H_

#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <arpa/inet.h>

#include <assert.h>
#include <err.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <netdb.h>
#include <poll.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>

#include <libssh2.h>
#include <libssh2_publickey.h>
#include <libssh2_sftp.h>

extern char *__progname;
class ssh2 {
   public:
      ssh2(std::string &, std::string &, const u_int16_t = 22);
      ssh2(const ssh2 &);
      ssh2 &operator= (const ssh2 &);
      ~ssh2();
      
      LIBSSH2_SESSION *GetSession(void) const;
      std::string GetUser(void) const;
      std::string GetHost(void) const;

      void Connect(int = 0);
      int Authenticate(std::string = "");
      void GetChannel(std::string = "", bool = false);

   protected:
      int _pkauth(std::string &);
      int _kiauth(std::string &);
      int _passauth(std::string = "");
      std::string _geterror(void);

      std::string _host;
      std::string _passkey;
      std::string _privkey;
      std::string _pubkey;
      std::string _user;
      std::string _version;

      int32_t _sock;
      int32_t _af;

      u_int32_t _port;
      LIBSSH2_SESSION *_session;
};

#endif
